package com.ruoyi.web.controller.classes.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.controller.classes.domain.AClasses;
import com.ruoyi.web.controller.classes.service.IAClassesService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 课程管理Controller
 *
 * @author G
 * @date 2025-04-28
 */
@RestController
@RequestMapping("/class/classes")
public class AClassesController extends BaseController
{
    @Autowired
    private IAClassesService aClassesService;

    /**
     * 查询课程管理列表
     */
    @PreAuthorize("@ss.hasPermi('class:classes:list')")
    @GetMapping("/list")
    public TableDataInfo list(AClasses aClasses)
    {
        startPage();
        List<AClasses> list = aClassesService.selectAClassesList(aClasses);
        return getDataTable(list);
    }

    /**
     * 导出课程管理列表
     */
    @PreAuthorize("@ss.hasPermi('class:classes:export')")
    @Log(title = "课程管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AClasses aClasses)
    {
        List<AClasses> list = aClassesService.selectAClassesList(aClasses);
        ExcelUtil<AClasses> util = new ExcelUtil<AClasses>(AClasses.class);
        util.exportExcel(response, list, "课程管理数据");
    }

    /**
     * 获取课程管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('class:classes:query')")
    @GetMapping(value = "/{classId}")
    public AjaxResult getInfo(@PathVariable("classId") Long classId)
    {
        return success(aClassesService.selectAClassesByClassId(classId));
    }

    /**
     * 新增课程管理
     */
    @PreAuthorize("@ss.hasPermi('class:classes:add')")
    @Log(title = "课程管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AClasses aClasses)
    {
        return toAjax(aClassesService.insertAClasses(aClasses));
    }

    /**
     * 修改课程管理
     */
    @PreAuthorize("@ss.hasPermi('class:classes:edit')")
    @Log(title = "课程管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AClasses aClasses)
    {
        aClassesService.getExam(aClasses.getClassId());
        //aClassesService.getClasses(aClasses.getClassId());
        return toAjax(aClassesService.updateAClasses(aClasses));
    }

    /**
     * 删除课程管理
     */
    @PreAuthorize("@ss.hasPermi('class:classes:remove')")
    @Log(title = "课程管理", businessType = BusinessType.DELETE)
	  @DeleteMapping("/{classIds}")
    public AjaxResult remove(@PathVariable Long[] classIds)
    {
      System.out.println("AClassesController.remove");
        return toAjax(aClassesService.deleteAClassesByClassIds(classIds));
    }

    /**
     * 按照登陆老师查询课程管理列表
     * @param aClasses
     * @return
     */
    @GetMapping("/list_t")
    public TableDataInfo list_t(AClasses aClasses)
    {
        startPage();
        aClasses.setTeacherId(getUserId());
        List<AClasses> list = aClassesService.selectAClassesList_t(aClasses);
        System.out.println("list_t:list = " + list);
        return getDataTable(list);
    }

    @GetMapping("/getAll")
    public TableDataInfo getAll()
    {
        startPage();
        List<Map<String,Object>> list = aClassesService.selectAClassesList_t_all();
        System.out.println("TableDataInfo:list = " + list);
        return getDataTable(list);
    }

    @GetMapping("/get_tea_info")
    public HashMap<String,Object> get_tea_info()
    {
        startPage();
        HashMap<String,Object> map = new HashMap<>();
        map.put("user_id",getUserId());
        map.put("dept_id",getDeptId());
        return map;
    }

  @GetMapping("/getFileList/{classId}")
  public TableDataInfo getFileList(@PathVariable("classId") String classId) {  // 直接使用Long类型
    System.out.println("classId = " + classId);
    startPage();
    List<Map<String,Object>> fileList = aClassesService.getFileList(Long.valueOf(classId));
    System.out.println("fileList = " + fileList);
    return getDataTable(fileList);
  }

}
